public class BinaryMatrix {
    public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix==null||matrix.length==0)
            return false;
        int len =matrix[0].length-1;
        int rowNum=matrix.length;
        for (int i=0;i<rowNum;i++)
        {
            if (matrix[i][0]>target||matrix[i][len]<target)
                continue;
            if (binary_search(matrix[i],target))
                return  true;
        }
        return false;
    }
    public boolean binary_search(int[] arr,int target){
        int len=arr.length-1;
        int left=0;
        int right=len;
        int mid;
        while (left<=right)
        {
            mid=(left+right)>>>1;
            if (arr[mid]==target)
                return true;
            if (arr[mid]>target)
            {
                right=mid-1;
            }
            else
            {
                left=mid+1;
            }
        }
        return false;

    }
}
